package com.gitee.wsl.struct.tree

import kotlin.test.Test

class QuickTreeHelperTest {

    @Test
    fun testMake(){
        val groupVo1= GroupVo("a",null);
        val groupVo2= GroupVo("b",null);
        val groupVo3= GroupVo("c","a");
        val groupVo4= GroupVo("d","b");
        val groupVos= listOf(groupVo1,groupVo2,groupVo3,groupVo4);
        val tree = QuickTreeHelper.makeTree(
            groupVos,GroupVo::parentGroupId,
            GroupVo::groupId,
            rootCheck = { x-> x.parentGroupId == null},
            setSubChildren = GroupVo::setSubGroupsList)
        println(tree)
    }

}
//定义GroupVo
 class GroupVo(val groupId:String,
               val parentGroupId:String?){
    var subGroups:List<GroupVo> = emptyList()

    fun setSubGroupsList(subList:List<GroupVo>){
        subGroups = subList
    }

    override fun toString(): String {
        return """
            groupId:$groupId,
            parentGroupId:$parentGroupId,
            child:$subGroups
        """.trimIndent()
    }
}


